﻿@model WishlistModel
@using Nop.Core
@using Nop.Core.Domain.Tax
@using Nop.Core.Infrastructure
@using Nop.Web.Models.ShoppingCart
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.Wishlist").Text);
}
<div class="page wishlist-page">
    <div class="page-title">
        <h1>
            @if (Model.IsEditable)
            {
                @T("Wishlist")
            }
            else
            {
                @String.Format(T("Wishlist.WishlistOf").Text, Model.CustomerFullname)
            }
        </h1>
    </div>
    <div class="page-body">
        <div class="wishlist-content" id="wish-list-module">
            @if (Model.Items.Count > 0)
            {
                if (Model.Warnings.Count > 0)
                {
                    <div class="message-error">
                        <ul>
                            @foreach (var warning in Model.Warnings)
                            {
                                <li>@warning</li>
                            }
                        </ul>
                    </div>
                }
                using (Html.BeginRouteForm("Wishlist", FormMethod.Post))
                {
                    <table class="cart-products-module">
                        <thead>
                            <tr class="cart-header-row">
                                @if (Model.ShowSku)
                                {
                                    <th class="sku">@T("ShoppingCart.SKU")</th>
                                }
                                @if (Model.ShowProductImages)
                                {
                                    <th class="picture">Picture</th>
                                }
                                <th class="products">@T("ShoppingCart.Product(s)")</th>
                                <th class="unitprice">@T("ShoppingCart.UnitPrice")</th>
                                <th class="qty">@T("ShoppingCart.Quantity")</th>
                                <th class="subtotal">@T("ShoppingCart.ItemTotal")</th>
                                @if (Model.IsEditable)
                                {
                                    <th>
                                        @T("ShoppingCart.Remove")
                                    </th>
                                }
                                @if (Model.DisplayAddToCart)
                                {
                                    <th>
                                        <span class="nobr">
                                            @T("ShoppingCart.AddToCart")
                                        </span>
                                    </th>
                                }
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model.Items)
                            {
                                <tr class="cart-item-row">
                                    @if (Model.ShowSku)
                                    {
                                        <td class="sku">@item.Sku</td>
                                    }
                                    @if (Model.ShowProductImages)
                                    {
                                        <td class="picture">
                                            <div>
                                                <img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" />
                                            </div>
                                        </td>
                                    }

                                    <td class="product">
                                        <div class="product-name">
                                            <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="@item.ProductName" class="product-name">@item.ProductName.ToStringLength(50)</a>
                                        </div>
                                        @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                        {
                                        <div class="product-attributes">
                                            @Html.Raw(item.AttributeInfo)
                                        </div>
                                        }
                                        @if (!String.IsNullOrEmpty(item.RecurringInfo))
                                        {
                                        <div class="recurring-info">
                                            @Html.Raw(item.RecurringInfo)
                                        </div>
                                        }
                                        @if (!String.IsNullOrEmpty(item.RentalInfo))
                                        {
                                        <div class="rental-info">
                                            @Html.Raw(item.RentalInfo)
                                        </div>
                                        }
                                        @if (item.Warnings.Count > 0)
                                        {
                                        <div class="message-error">
                                            <ul>
                                                @for (int i = 0; i < item.Warnings.Count; i++)
                                                    {
                                                    <li>@item.Warnings[i]</li>
                                                    }
                                            </ul>
                                        </div>
                                        }
                                    </td>
                                    <td class="unitprice">
                                        <span class="amount">@item.UnitPrice</span>
                                    </td>
                                    <td class="qty">
                                        <div class="wrap">
                                            @if (Model.IsEditable)
                                            {
                                                if (item.AllowedQuantities.Count > 0)
                                                {
                                            <select name="itemquantity@(item.Id)" class="qty-dropdown form-control">
                                                @foreach (var qty in item.AllowedQuantities)
                                                        {
                                                        <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                                        }
                                            </select>
                                                }
                                                else
                                                {
                                            <span data-action="decrease" class="decrease">-</span>
                                            <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="value qty-input" />
                                            <span data-action="increase" class="increase">+</span>
                                                }
                                            }
                                            else
                                            {
                                            <span class="value">@item.Quantity</span>
                                            }
                                        </div>
                                    </td>
                                    <td class="subtotal">
                                        <span class="amount">@item.SubTotal</span>
                                        @if (!String.IsNullOrEmpty(item.Discount))
                                        {
                                        <div class="discount">
                                            @T("ShoppingCart.ItemYouSave"): @item.Discount
                                        </div>
                                        }
                                    </td>
                                    @if (Model.IsEditable)
                                    {
                                        <td class="remove-from-cart">
                                            <span class="td-title">@T("ShoppingCart.Remove"):</span>
                                            <input type="checkbox" name="removefromcart" class="remove-chkbox" value="@(item.Id)" />
                                        </td>
                                    }
                                    @if (Model.DisplayAddToCart)
                                    {
                                        <td class="add-to-cart-from-wishlist">
                                            <span class="td-title">@T("ShoppingCart.AddToCart"):</span>
                                            <input type="checkbox" name="addtocart" value="@(item.Id)" />
                                        </td>
                                    }
                                </tr>
                            }
                        </tbody>
                    </table>
                    <div class="buttons">
                        <div class="common-buttons">
                            @if (Model.IsEditable)
                            {
                                <input type="submit" name="updatecart" value="@T("Wishlist.UpdateCart")" id="update-wishlist-button" class="btn btn-default btn-xs update-wishlist-button" />
                            }
                            @if (Model.DisplayAddToCart)
                            {
                                <input type="submit" name="addtocartbutton" value="@T("ShoppingCart.AddToCart")" class="btn btn-default btn-xs wishlist-add-to-cart-button" />
                            }
                            @if (Model.IsEditable && Model.EmailWishlistEnabled)
                            {
                                <input type="button" value="@T("Wishlist.EmailAFriend")" class="btn btn-default btn-xs email-a-friend-wishlist-button" onclick="location.href='@Url.RouteUrl("EmailWishlist")'" />
                            }
                        </div>
                    </div>
                }
            }
            else
            {
                @T("Wishlist.CartIsEmpty")
            }
        </div>
        @if (Model.IsEditable && Model.Items.Count > 0)
        {
            <div class="share-info">
                <p>
                    <span class="share-label">@T("Wishlist.YourWishlistURL"):</span>
                </p>
                <p>
                    <a href="@Url.RouteUrl("Wishlist", new { customerGuid = Model.CustomerGuid })" class="share-link">@Url.RouteUrl("Wishlist", new { customerGuid = Model.CustomerGuid }, "http")</a>
                </p>
            </div>
            <script type="text/javascript">
                seajs.use("common/1.0.0/index", function (app) {
                    app(function () {
                        var $wishlistlist = app("#wish-list-module");
                        // delegate increase, decrease button.
                        $wishlistlist.on("click", "span[data-action]", function () {
                            var $this = app(this);
                            var action = $this.data("action");
                            if (action == "increase") {
                                // plus.
                                var $qtyInput = $this.prev("input.qty-input");
                                var orginVal = parseInt($qtyInput.val());
                                $qtyInput.val(++orginVal);
                            } else {
                                var $qtyInput = $this.next("input.qty-input");
                                var orginVal = parseInt($qtyInput.val());
                                if (orginVal > 1) {
                                    $qtyInput.val(--orginVal);
                                }
                            }
                        });
                        // delegate remove button.
                        $wishlistlist.on("click", "input.remove-chkbox", function () {
                            // trigger form update button.
                            var $wishlistUpdateBtn = app("#update-wishlist-button");
                            if ($wishlistUpdateBtn.length) {
                                $wishlistUpdateBtn.trigger("click");
                            }
                        });
                    });
                });
            </script>
        }
    </div>
</div>
